<template>
  <div class="cart-container">
    <div class="cart-header">
      <h1>购物车</h1>
    </div>
    
    <div class="cart-content">
      <el-table :data="cartItems" style="width: 100%">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="商品" width="400">
          <template slot-scope="scope">
            <div class="product-info">
              <div class="product-image"></div>
              <div class="product-details">
                <h3>{{ scope.row.name }}</h3>
                <p class="description">{{ scope.row.description }}</p>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="price" label="单价" width="120"></el-table-column>
        <el-table-column label="数量" width="150">
          <template slot-scope="scope">
            <el-input-number 
              v-model="scope.row.quantity" 
              :min="1" 
              :max="10"
              size="small">
            </el-input-number>
          </template>
        </el-table-column>
        <el-table-column label="小计" width="120">
          <template slot-scope="scope">
            ¥{{ scope.row.price * scope.row.quantity }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="120">
          <template slot-scope="scope">
            <el-button type="text" @click="removeItem(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      
      <div class="cart-footer">
        <div class="total">
          <span>总计：</span>
          <span class="price">¥{{ totalPrice }}</span>
        </div>
        <el-button type="primary" size="large">结算</el-button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Cart',
  data() {
    return {
      cartItems: [
        {
          name: '小米手机',
          description: '高性能智能手机',
          price: 1999,
          quantity: 1
        },
        {
          name: '小米笔记本',
          description: '轻薄本',
          price: 4999,
          quantity: 1
        }
      ]
    }
  },
  computed: {
    totalPrice() {
      return this.cartItems.reduce((total, item) => {
        return total + item.price * item.quantity
      }, 0)
    }
  },
  methods: {
    removeItem(item) {
      const index = this.cartItems.indexOf(item)
      if (index > -1) {
        this.cartItems.splice(index, 1)
      }
    }
  }
}
</script>

<style scoped>
.cart-container {
  max-width: 1226px;
  margin: 0 auto;
  padding: 20px;
}

.cart-header {
  margin-bottom: 30px;
}

.cart-header h1 {
  font-size: 24px;
  color: #333;
}

.product-info {
  display: flex;
  align-items: center;
}

.product-image {
  width: 80px;
  height: 80px;
  background-color: #f5f5f5;
  margin-right: 15px;
}

.product-details h3 {
  font-size: 16px;
  color: #333;
  margin-bottom: 5px;
}

.description {
  font-size: 14px;
  color: #666;
}

.cart-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.total {
  margin-right: 20px;
  font-size: 16px;
}

.price {
  color: #ff6700;
  font-size: 20px;
  font-weight: bold;
}
</style> 